﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YArchitech.Controls;
using YJKExcelTableUtil;
using YJKRevitView;

namespace YJKInspectModel.PerformanceAnalysis.AreaRatioWindowToWall
{
	[Transaction(TransactionMode.Manual)]
	internal class CmdAreaRatioWindowToWall : IExternalCommand
	{
		public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
		{
			Document document = commandData.Application.ActiveUIDocument.Document;
			if (SwitchView.SetUsableView(CmdViewType.FloorPlan, commandData) != Autodesk.Revit.UI.Result.Succeeded)
			{
				return Autodesk.Revit.UI.Result.Failed;
			}
			new RelationWindowToWall(document);
			RelationWindowToWall.RelationWindowToWallInit();
			Dictionary<int, List<FamilyInstance>> doorAndWindowList = RelationWindowToWall.DoorAndWindowList;
			FacadeMaker facadeMaker = new FacadeMaker(document);
			facadeMaker.GetTrueNorth();
			facadeMaker.MakeAllFacade();
			ResultMaker resultMaker = new ResultMaker(commandData, document, facadeMaker);
			resultMaker.GetGradeLevel();
			if (resultMaker.GradeLevel == null)
			{
				YJKMessageBox.Show("模型中未能检索到室外地坪标高！");
				return Autodesk.Revit.UI.Result.Failed;
			}
			resultMaker.GetAllEffectiveFloorViewPlan();
			if (resultMaker.FloorPlanViews.Count < 0)
			{
				YJKMessageBox.Show("模型中没有楼层平面试图无法进行窗墙比计算！");
				return Autodesk.Revit.UI.Result.Failed;
			}
			resultMaker.AreaRatioStructMakerListInit();
			AreaRatioExportToView areaRatioExportToView = new AreaRatioExportToView(document, resultMaker);
			areaRatioExportToView.CalAreaRatio();
			areaRatioExportToView.AreaRatioGridInit();
			new GridToolExportImportRevit(commandData, areaRatioExportToView.AreaRatioGrid, "", 7, 2, CREATENEWVIEW.CURRENT).DrawInRevitView();
			return Autodesk.Revit.UI.Result.Succeeded;
		}
	}
}
